<template>
    <div class="storage">
        <el-card class="!border-none" shadow="never">
            <el-alert
                type="warning"
                title="温馨提示：1.切换存储方式后，需要将资源文件传输至新的存储端；2.请勿随意切换存储方式，可能导致图片无法查看"
                :closable="false"
                show-icon
            ></el-alert>
        </el-card>
        
        
        <el-card class="!border-none mt-4" shadow="never" v-loading="state.loading">
            
            
            <el-table size="large" :data="state.lists">
                <el-table-column label="储存方式" prop="name" min-width="120"/>
                <el-table-column label="储存位置" prop="describe" min-width="160"/>
                <el-table-column label="状态" min-width="80">
                    
                    
                    <template #default="{ row }">
                        <el-tag v-if="row.status == 1">开启</el-tag>
                        <el-tag type="danger" v-else>关闭</el-tag>
                    </template>
                
                
                </el-table-column>
                
                
                <el-table-column label="操作" min-width="80" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['setting:storage:edit']"
                            type="primary"
                            link
                            @click="handleSet(row.alias)"
                        >
                            设置
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        
        <edit-popup ref="editRef" @success="getLists"/>
    </div>
</template>
<script lang="ts" setup name="storage">

import EditPopup from "@/views/system/storage/edit.vue";

const editRef = shallowRef<InstanceType<typeof EditPopup>>()

// 列表数据
import {storageList} from "@/api/system/SystemConfigService";

const state = reactive({
    loading: false,
    lists: []
})


// 获取存储引擎列表数据
const getLists = async () => {
    try {
        state.loading = true
        state.lists = await storageList()
        state.loading = false
    } catch (error) {
        state.loading = false
    }
}

/**
 * 打开配置
 *
 * @author 徐寿春
 * 2023/7/19 13:24
 */
function handleSet(alias: string) {
    editRef.value?.open(alias)
}


getLists()
</script>
